# Author:Zhang Yu

def get_user():
    user_list = []
    for user in open("user.txt","r"):
        line = user.splitlines()
        user_list.append(line[0].split(","))
    return user_list


def get_black_name():
    with open("black_name.txt","r") as b:
        line = b.splitlines()

def check_user(username,password):
    valid_user = True
    msg = "欢迎{name}登录 !".format(name= username)
    user_list = get_user()
    #print(user_list)

    for user in user_list:
        #print(user)
        name , pwd = user
        if username != name:

            msg = "用户名不正确"
            valid_user = False
        elif password != pwd:
            msg = "密码不正确"
            valid_user = False
    return (valid_user,msg)

count = 0
def login():
    username = input("username :")
    pwd = input("pwd :")

    with open("black_name.txt", "r") as n:
        print(n.readlines())
        if username in n.readlines():
            return (False,"当前用户已被锁定")
    result = check_user(username,pwd)
    if result[0] is False :
        count =+ 1
    else:
        count = 0
    if count == 3 :
        file = open("black_name.txt","a")
        file.write(username)
    return result


if __name__ == '__main__':
    if "zhangyu" in ['zhangyu']:
        print("YES")
    while True :
        result = login()
        print(result[1])
        if result[0]:
            break



